package com.jt.ktdemo.adapter

import android.content.Context
import android.view.View
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.jt.ktdemo.R
import com.jt.ktdemo.bean.ObtainMessageBean
import com.jt.ktdemo.utils.LogUtil

class MessageHomeAdapter(layoutResId: Int, data: ArrayList<ObtainMessageBean>, context: Context) :
    BaseQuickAdapter<ObtainMessageBean, BaseViewHolder>(layoutResId, data) {

    private var datas = ArrayList<ObtainMessageBean>()
    private var aContext: Context? = null

    init {
        aContext = context
        datas = data
    }

    override fun convert(helper: BaseViewHolder, item: ObtainMessageBean) {
        //标题赋值
        LogUtil.e("item的type-->" + item.type)
        when (item.type) {
            "system" ->
                helper.setText(R.id.tvModuleTitle, "System infomation")
            "report" ->
                helper.setText(R.id.tvModuleTitle, "Report message")
        }



        //消息数量赋值
        helper.setText(R.id.tvModuleMessageNumber, item.number)

        //消息内容赋值
        helper.setText(R.id.tvModuleMessageContext, item.context)

        //消息时间
        helper.setText(R.id.tvModuleDate, item.time)

        when (item.type) {
            "system" ->
                Glide.with(aContext!!).load(R.drawable.icon_module_small_heart)
                    .into((helper.getView<View>(R.id.imageView4) as ImageView))
            "report" ->
                Glide.with(aContext!!).load(R.drawable.logo1)
                    .into((helper.getView<View>(R.id.imageView4) as ImageView))
        }


    }

    fun addListData(data: MutableList<ObtainMessageBean>) {
        val size = datas.size
        datas.addAll(size, data)
        notifyItemRangeChanged(size, data.size)
    }
}